//
//  ViewController.swift
//  AttributedStringHelper
//
//  Created by fanxiaoxin_1987@126.com on 11/01/2021.
//  Copyright (c) 2021 fanxiaoxin_1987@126.com. All rights reserved.
//

import UIKit
import UICreate
import AttributedStringHelper

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let text = NSMutableAttributedString("This is a text", .color(.blue), .boldFont(size: 16))
        text.set(.color(.red))
        text.set(.color(.purple), for: "t")
        text.set(.color(.green), at: 2, count: 2)
        text.set(.color(.darkGray), regex: "\\bi")
        text.insert(.color(.systemOrange), for: " haha ", at: 10)
        text.insert(UIImage(named: "icon"), bounds: CGRect(origin: .zero, size: CGSize(width: 16, height: 16)), at: 13)
        text.append(.color(.systemRed), .boldFont(size: 20), for: "我是新字啊")
        
        let text2 = NSMutableAttributedString(.color(.blue), .font(size: 15)) {
            "这是一段文字"
            "这是另一段文字".attr(.color(.red))
            "ab"
            "cd".attr(.color(.purple))
            UIImage(named: "icon")
            "ef"
        }
        
        let text3 = "I am a string".asAttributed(.color(.blue), .italicFont(size: 12))
        
        self.view.build {
            UIStackView(.axis(.vertical), .alignment(.fill), .distribution(.fillEqually)).build {
                UILabel(.text(text))
                UILabel(.text(text2))
                UILabel(.text(text3))
                UILabel(.text(.create("create from \("wha\("hehe", .shadow(offset: .zero, radius: 4), .kern(4))t", .color(.red)) not mutable", .color(.lightGray), .font(size: 18, weight: .heavy))))
            }.layout(.centerY, .marginX)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

